{mtemplate '_header'}
<div class="dm-subnav">
	<div class="subnav-title">门店信息</div>
	<ul>
		<li class="{if $operation == 'basic'}active{/if}"><a href="{php echo manage_url(array('r'=>'store','ac'=>'settings','op'=>'basic'))}">基础设置</a></li>
		<li class="{if $operation == 'enough'}active{/if}"><a href="{php echo manage_url(array('r'=>'store','ac'=>'settings','op'=>'enough'))}">满减设置</a></li>
		
		
	</ul>
</div>
<div class="dm-container">
	<div class="dm-content">
		<style type="text/css">
			.pl0{padding-left: 0px;}
			.mt10{margin-top: 10px}
			.ml15{margin-left: 15px}
		</style>
		{if $operation == 'basic'}
		<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=HYVBZ-RFTAF-ESEJ6-NDOTJ-2QLIQ-PFFFY"></script>
		<form action="" method="post" class="form-horizontal form" id="form">
		<input type="hidden" name="id" value="{$store['id']}">
		    <div class="panel we7-panel panel-default">
		        <ul class="we7-page-tab" id="myTab" style="margin-left: 0;margin-right: 0">
		            <li class="active"><a href="#tab_basic">基本</a></li>
		            <li><a href="#tab_order">订单设定</a></li>
		            <li><a href="#tab_takeout">外卖设置</a></li>
		        </ul>
		        <div class="tab-content">
		            <div class="tab-pane active" id="tab_basic">
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">门店名称</label>
		                    <div class="col-md-6">
		                    	{if $readonly}
		                    	<p class="form-control-static">{$store['name']}</p>
		                    	{else}
		                        <input type="text" name="store[name]" class="form-control" value="{$store['name']}" />
		                    	{/if}
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red"></span>门店地址</label>
		                    <script type="text/javascript">
		                        require(["jquery", "district"], function($, dis){
		                            $(".tpl-district-container").each(function(){
		                                var elms = {};
		                                elms.province = $(this).find(".tpl-province")[0];
		                                elms.city = $(this).find(".tpl-city")[0];
		                                elms.district = $(this).find(".tpl-district")[0];
		                                var vals = {};
		                                vals.province = $(elms.province).attr("data-value");
		                                vals.city = $(elms.city).attr("data-value");
		                                vals.district = $(elms.district).attr("data-value");
		                                dis.render(elms, vals, {withTitle: true});
		                            });
		                        });
		                    </script>
		                    <div class="col-sm-9 col-xs-12 tpl-district-container pl0">
		                        <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
		                            <select name="store[province]" data-value="{$store['province']}" class="form-control tpl-province">
		                            </select>
		                        </div>
		                        <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
		                            <select name="store[city]" data-value="{$store['city']}" class="form-control tpl-city">
		                            </select>
		                        </div>
		                        <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
		                            <select name="store[district]" data-value="{$store['district']}" class="form-control tpl-district" onchange="codeAddress();">
		                            </select>
		                        </div>
		                    </div>
		                    <div class="col-sm-6 col-sm-offset-2 pl0" style="margin-top:15px;padding-left: 15px">
		                        <div class="col-sm-8 pl0">
		                            <div class="input-group">
		                            	<div class="input-group-addon"><input type="checkbox" id="district_edit_self" name="store[district_edit_self]" value="1" {if $store['district_edit_self']} checked="" {/if}/> 自填区县</div>
		                                <input type="text" name="store[address]" class="form-control valid inline address" value="{$store['address']}" placeholder="请输入详细地址，请勿重复填写市区信息">
		                                <div class="input-group-btn"><button type="button" title="搜索" onclick="codeAddress();" class="btn btn-default"><i class="fa fa-search"></i></button></div>
		                            </div>
		                        </div>
		                    </div>
		                    <div class="col-sm-6 col-sm-offset-2 pl0"><div class="help-block mt10 ml15">注意：这个只是模糊定位，准确位置请地图上标注。 最多50字。</div></div>
		                    <div class="col-sm-6 col-sm-offset-2 pl0" style="margin-top:15px;width: 474px;height: 300px; ">
		                        <div id="container" style="position: absolute;margin-left:15px;width: 474px; height: 300px;border: 1px solid #e5e6e7;overflow:hidden;">
		                        </div>
		                    </div>
		                    <script>
		                    var geocoder,map,marker = null;
		                    var markersArray = [];
		                    var marker = new qq.maps.Marker();
		                    var init = function() {
		                        var center = new qq.maps.LatLng(39.916527,116.397128);
		                        map = new qq.maps.Map(document.getElementById('container'),{
		                            center: center,
		                            zoom: 13
		                        });
		                        //调用地址解析类
		                        geocoder = new qq.maps.Geocoder({
		                            complete : function(result){
		                                map.setCenter(result.detail.location);

		                                marker = new qq.maps.Marker({
		                                    map:map,
		                                    position: result.detail.location,
		                                    draggable: true,
		                                });
		                                console.log(result);
		                                $(".longitude").val(result.detail.location.lng);
		                                $(".latitude").val(result.detail.location.lat);
		                                qq.maps.event.addListener(marker, 'dragend', function(e) {
		                                    $(".longitude").val(e.latLng.lng);
		                                    $(".latitude").val(e.latLng.lat);
		                                });
		                            }
		                        });
		                        {if !empty($store['longitude']) && !empty($store['latitude'])}
		                        map.setCenter(new qq.maps.LatLng({$store['latitude']},{$store['longitude']}));
		                        marker = new qq.maps.Marker({
		                            position: new qq.maps.LatLng({$store['latitude']},{$store['longitude']}),
		                            map: map,
		                          draggable: true,
		                        });
		                        // setTimeout(function(){
		                        //  codeAddress();
		                        // },3000);
		                        {/if}
		                    }

		                    init();
		                    function clearOverlays() {
		                        if (markersArray) {
		                            for (i in markersArray) {
		                                markersArray[i].setMap(null);
		                            }
		                        }
		                    }
		                    function codeAddress() {
		                        if($('#district_edit_self').is(':checked')){
		                            var address = $('.tpl-province').val()+$('.tpl-city').val() + $(".address").val();
		                        }else{
		                            var address = $('.tpl-province').val()+$('.tpl-city').val()+$('.tpl-district').val()+ $(".address").val();
		                        }
		                        //通过getLocation();方法获取位置信息值
		                        marker.setMap(null);
		                        geocoder.getLocation(address);
		                    }

		                    </script>
		                    <div class="col-sm-9 col-sm-offset-2 pl0" style="margin-top:15px;">
		                                    
		                        <div class="col-xs-4 col-sm-4">
		                            <input type="text" name="store[longitude]" value="{$store['longitude']}" readonly="" placeholder="地理经度"  class="form-control longitude" />
		                        </div>
		                        <div class="col-xs-4 col-sm-4">
		                            <input type="text" name="store[latitude]" value="{$store['latitude']}" readonly="" placeholder="地理纬度"  class="form-control latitude" />
		                        </div>
		                        <div class="help-block"></div>
		                    </div>
		                    
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店类型</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class="checkbox-inline">
		                            <input type="checkbox" name="store[is_getself]" value="1" {if $store['is_getself']=='1' || $store['is_getself'] == ''} checked=""{/if}> 自取/店内点餐
		                        </label>
		                        <label class="checkbox-inline">
		                            <input type="checkbox" name="store[is_takeout]" value="1" {if $store['is_takeout']=='1' || $store['is_takeout'] == ''} checked=""{/if}> 外卖
		                        </label>
		                        <div class="help-block">至少选择一个</div>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店状态</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class="radio-inline">
		                            <input type="radio" name="store[status]" value="1" {if $store['status']=='' || $store['status'] == '1'} checked=""{/if}> 营业
		                        </label>
		                        <label class="radio-inline">
		                            <input type="radio" name="store[status]" value="0" {if $store['status']=='0'} checked=""{/if}> 关店
		                        </label>
		                        <label class="radio-inline">
		                            <input type="radio" name="store[status]" value="2" {if $store['status']=='2'} checked=""{/if}> 隐藏
		                        </label>
		                        <div class="help-block">选择隐藏后，用户列表不可见</div>
		                    </div>
		                </div>
		                <div class="form-group store-closed" {if $store['status']=='' || $store['status'] == '1' || $store['status'] == '2'} style="display: none"{/if}>
		                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">关店原因</label>
		                    <div class="col-md-6">
		                        <input type="text" name="store[close_reason]" class="form-control" value="{$store['close_reason']}" />
		                    </div>
		                </div>
		                <div class="form-group store-opening" {if $store['status']=='0'} style="display: none" {/if}>
		                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">门店营业时间</label>
		                    <div class="col-sm-8 col-xs-12">
		                        <div class="col-sm-5 col-xs-5 pl0" style="padding-right: 5px">
		                            {php echo tpl_form_field_clock('store[starttime]',$store['starttime']);}
		                        </div>
		                        <span style="float: left;line-height: 34px;color: #98999a;">-</span>
		                        <div class="col-sm-5 col-xs-5" style="padding-left: 5px">
		                            {php echo tpl_form_field_clock('store[endtime]',$store['endtime']);}
		                        </div>
		                        <div style="clear: both;"></div>
		                        <div class="help-block">如24小时营业请设置为00:00-00:00</div>
		                    </div>
		                </div>
						<div class="form-group store-opening" {if $store['status']=='0'} style="display: none" {/if}>
							<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">外卖单独设置营业时间</label>
							<div class="col-sm-9 col-xs-12">
								<label class="radio-inline">
									<input type="radio" name="store[takeout_open_time][status]" value="1" {if $store['takeout_open_time']['status'] == '1'} checked=""{/if}> 单独设置
								</label>
								<label class="radio-inline">
									<input type="radio" name="store[takeout_open_time][status]" value="0" {if $store['takeout_open_time']['status']=='0' || $store['takeout_open_time']['status']==''} checked=""{/if}> 不设置
								</label>
							</div>
						</div>
						<div class="form-group store-opening takeout-open-time" {if $store['takeout_open_time']['status'] == '0' || $store['takeout_open_time']['status'] == ''} style="display: none"{/if} >
							<label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">外卖营业时间</label>
							<div class="col-sm-8 col-xs-12">
								<div class="col-sm-5 col-xs-5 pl0" style="padding-right: 5px">
									{php echo tpl_form_field_clock('store[takeout_open_time][starttime]',$store['takeout_open_time']['starttime']);}
								</div>
								<span style="float: left;line-height: 34px;color: #98999a;">-</span>
								<div class="col-sm-5 col-xs-5" style="padding-left: 5px">
									{php echo tpl_form_field_clock('store[takeout_open_time][endtime]',$store['takeout_open_time']['endtime']);}
								</div>
								<div style="clear: both;"></div>
								<div class="help-block">如24小时营业请设置为00:00-00:00</div>
							</div>
						</div>
		                <div class="form-group store-closed" {if empty($settings['sms_status'])} style="display: none"{/if}>
		                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">订单短信通知</label>
		                    <div class="col-md-6">
		                        <input type="text" name="store[notice_tel]" class="form-control" value="{$store['notice_tel']}" />
		                        <div class="help-block">多个手机号请用英文逗号“,”隔开</div>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">顶部标题栏背景色</label>
		                    <div class="col-sm-8 col-xs-12">
		                        {php echo tpl_form_field_color('store[bg_color]',empty($store['bg_color']) ? '#000000' : $store['bg_color']);}
		                        <div class="help-block"><font color="#FF0000">默认为#000000</font></div>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">顶部标题栏前景色</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class="radio-inline">
		                            <input type="radio" name="store[fg_color]" value="#ffffff" {if $store['fg_color']=='' || $store['fg_color'] == '#ffffff'} checked=""{/if}> 白色
		                        </label>
		                        <label class="radio-inline">
		                            <input type="radio" name="store[fg_color]" value="#000000" {if $store['fg_color']=='#000000'} checked=""{/if}> 黑色
		                        </label>
		                        <div class="help-block">包括按钮、标题、状态栏的颜色，仅支持 白色 和 黑色</div>
		                    </div>
		                </div>
		                <!-- <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">门店顶部幻灯片</label>
		                    <div class="col-md-6">
		                        {php echo tpl_form_field_multi_image('store[imgs]',$store['imgs']);}
		                        <div class="help-block">图片建议长宽保持一致。建议尺寸640*350</div>
		                    </div>
		                </div> -->
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">订单备注提示</label>
		                    <div class="col-md-6">
		                        <input type="text" name="store[remark_text]" class="form-control" value="{$store['remark_text']}" />
		                        <div class="help-block">如：如有口味要求，请输入备注</div>
		                    </div>
		                </div>
		            </div>
		            <div class="tab-pane" id="tab_order">
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">开启自动接单</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class="radio-inline">
		                            <input type="radio" name="store[auto_order]" value="1" {if $store['auto_order']=='' || $store['auto_order'] == '1'} checked=""{/if}> 开启
		                        </label>
		                        <label class="radio-inline">
		                            <input type="radio" name="store[auto_order]" value="0" {if $store['auto_order']=='0'} checked=""{/if}> 关闭
		                        </label>
		                        <div class="help-block">开启此功能后用户支付成功自动接单</div>
		                    </div>
		                </div>
		            </div>
		            <div class="tab-pane" id="tab_takeout">
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">外卖起送价</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <div class="input-group">
		                            <input type="text" class="form-control" name="store[start_price]" value="{$store['start_price']}">
		                            <span class="input-group-addon">元</span>
		                        </div>
		                        <div class="help-block">0为不限制</div>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">派送范围</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <div class="input-group">
		                            <input type="text" class="form-control" name="store[send_limit]" value="{$store['send_limit']}">
		                            <span class="input-group-addon">公里内，配送费</span>
		                            <input type="text" class="form-control" name="store[send_fee]" value="{$store['send_fee']}">
		                            <span class="input-group-addon">元</span>
		                        </div>
		                        <div class="help-block">以店铺地址为中心点的半径范围</div>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择配送方式</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <label class="radio-inline">
		                            <input type="radio" name="store[deliver_type]" value="0" {if empty($store['deliver_type']) || empty($settings['deliver_dada_status'])} checked=""{/if}> 商家配送
		                        </label>
		                        <label class="radio-inline">
		                            <input {if empty($settings['deliver_dada_status'])} disabled="" {/if} type="radio" name="store[deliver_type]" value="1" {if $store['deliver_type']=='1' && $settings['deliver_dada_status'] == '1'} checked=""{/if}> 达达配送
		                        </label>
		                        <div class="help-block"></div>
		                    </div>
		                </div>
		                <div class="deliver-dada" {if empty($store['deliver_type']) || empty($settings['deliver_dada_status'])} style="display: none"{/if}>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店编号</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <input type="text" name="store[deliver_dada_shopno]" class="form-control" value="{$store['deliver_dada_shopno']}" />
		                        <div class="help-block">请至http://newopen.imdada.cn注册账号并创建门店</div>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店所在城市区号</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <input type="text" name="store[deliver_dada_citycode]" class="form-control" value="{$store['deliver_dada_citycode']}" />
		                        <div class="help-block">如南京：025</div>
		                    </div>
		                </div>
		                </div>
		            </div>
		        </div>
		    </div>
		    
			{if empty($readonly)}
			<div class="form-group col-sm-12" style="margin-left: -15px;">
				<input type="hidden" name="id" value="{$store['id']}" />
				<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
			{/if}
		</form>
		<script type="text/javascript">
		$(function () {
		    window.optionchanged = false;
		    $('#myTab a').click(function (e) {
		        e.preventDefault();//阻止a链接的跳转行为
		        $(this).tab('show');//显示当前选中的链接及关联的content
		    })

		});
		{if $readonly}
		$('#form input,#form select').attr("disabled","disabled");
		{/if}
		$('input[name="store[status]"]').click(function(){
		    var storeStatus = $(this).val();
		    if(storeStatus == 1){
		        $('.store-opening').show();
		        $('.store-closed').hide();
		    }else if(storeStatus == 0){
		        $('.store-closed').show();
		        $('.store-opening').hide();
		    }else if(storeStatus == 2){
		        $('.store-closed').hide();
		        $('.store-opening').show();
		    }
		});
		$('input[name="store[takeout_open_time][status]"]').click(function(){
			var status = $(this).val();
			if(status == 1){
				$('.takeout-open-time').show();
			}else if(status == 0){
				$('.takeout-open-time').hide();
			}
		});
		$('input[name="store[deliver_type]"]').click(function(){
		    var deliver = $(this).val();
		    if(deliver == 1){
		        $('.deliver-dada').show();
		    }else{
		        $('.deliver-dada').hide();
		    }
		})
		$('#form').submit(function(){
		    if((!$('input[name="store[is_getself]"]').is(':checked')) && (!$('input[name="store[is_takeout]"]').is(':checked'))){
		        util.message("门店类型必须选择一个！");
		        return false;
		    }
		    return true;
		});
		</script>
		{elseif $operation == 'enough'}
		<form action="" method="post" class="form-horizontal form" id="form">
		<div class="form-group">
		    <div class="col-sm-9 col-xs-12">
                <div class="input-group">
                    <span class="input-group-addon">单笔订单满</span>
                    <input type="text" class="form-control" name="store[enoughmoney]" value="{$store['enoughmoney']}">
                    <span class="input-group-addon">元，减</span>
                    <input type="text" class="form-control" name="store[enoughdeduct]" value="{$store['enoughdeduct']}">
                    <span class="input-group-addon">元</span>
                </div>
                <div class="help-block">两个值都设置才生效，最低消费必须大于减免金额</div>
            </div>
		</div>
		<div class="form-group col-sm-12">
		    <input type="hidden" name="id" value="{$store['id']}" />
		    <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
		    <input type="hidden" name="token" value="{$_W['token']}" />
		</div>
		</form>
		{/if}
	</div>
</div>
{mtemplate '_footer'}